#include <iostream>
#include <algorithm>
using namespace std;
struct data
{
	int begin;
	int end;
};
data src[10000];

bool cmp(data a,data b)
{
	return a.end<b.end;
}
int main()
{
	int t;
	cin>>t;
	for(int i=0;i<t;i++){
		int m;
		cin>>m;
		for(int j=0;j<m;j++){
			cin>>src[j].begin>>src[j].end;
		}
		sort(src,src+m,cmp);
		int count=1;
		int now=0;
		for(int k=1;k<m;k++){
			if(src[k].begin>src[now].end){
				count++;
				now=k;
			}
		}
		cout<<count<<endl;
	}
}
